package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Aspect //表示该类是一个切面类
public class TimeAspect {


    /**
     * 统计每个方法的耗时
     * @param joinPoint 通过反射的方式封装了原始方法
     * @return  原始方法的 返回值是什么就返回什么
     */
    // @Around("execution(* com.itheima.controller.DeptController.*(..))")
    public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
        long startTime = System.currentTimeMillis();
        Object result = joinPoint.proceed();
        long endTime = System.currentTimeMillis();
        log.info("Time taken: {} ms", endTime - startTime);
        return result;
    }

}
